package com.gzc.pm.logic
{
	import cn.skyclass.controls.AdvancedAlert;
	import cn.skyclass.net.BaseSubmitter;
	import cn.skyclass.net.OperationResult;
	
	import com.gzc.pm.bean.DetsetbBean;
	import com.gzc.pm.bean.ProcessRouteBean;
	import com.gzc.pm.dao.ToleranceDao;
	
	import mx.rpc.events.ResultEvent;
	import mx.utils.StringUtil;
	
	public class ToleranceEditor extends BaseSubmitter
	{
		/**
		 * 公差编辑
		 */
		
		public function ToleranceEditor(proc:ProcessRouteBean, detsetb:DetsetbBean, uslStr:String, lslStr:String)
		{
			_proc = proc;
			_detsetb = detsetb;
			_uslStr = uslStr;
			_lslStr = lslStr;
		}
		
		private var _proc:ProcessRouteBean;
		private var _detsetb:DetsetbBean;
		private var _uslStr:String;
		private var _lslStr:String;
		
		override public function validate():String{
			if(!_detsetb){
				return '请选择一个检测项！';
			}
			if(StringUtil.trim(_uslStr).length==0){
				return '请输入USL！';
			}
			if(StringUtil.trim(_lslStr).length==0){
				return '请输入LSL！';
			}
			
			return null;
		}
		
		override protected function doSubmit():void{
			var toleranceDao:ToleranceDao = new ToleranceDao();
			toleranceDao.insertOrUpdateTolerance(_proc.prId, _detsetb, Number(_uslStr), Number(_lslStr), onSubmitted);
		}
		private function onSubmitted(e:ResultEvent):void{
			var result:OperationResult = e.result as OperationResult;
			if(result.successful){
				reloadToleraces();
				dispatchSubmittedEvent();
			}else{
				AdvancedAlert.info('设置公差值失败！');
				dispatchFailedEvent();
			}
		}
		private function reloadToleraces():void{
			var toleranceLoader:ToleranceLoader = new ToleranceLoader();
			toleranceLoader.load();
		}
		
	}
}